﻿<cfsilent>
	<cfsetting requesttimeout="90" />
	<cfscript>

		termId = event.getArg("TermID");
		courseId = event.getArg("CID");

		sessionAdvice = getProperty("serviceFactory").getBean("sessionAdvice");
		mathAdvice = getProperty("serviceFactory").getBean("senateMathAdvice");

		/* 学籍相关信息 */
		studentId = sessionAdvice.getAutherUserID();
		//studentClassId = sessionAdvice.getUserProp("studentClass");
		//studentSubjectId = sessionAdvice.getUserProp("studentSubject");
		//studentDirId = sessionAdvice.getUserProp("studentSubDir");
		//studentGrade = sessionAdvice.getUserProp("studentGrade");
		//studentDepartment = sessionAdvice.getUserProp("studentDepartment");
		
		rs_task = queryNew("tsk_id");

		if ( len(studentId) and len(termId) and len(courseId) ) {
			
			/* 读取课程类别 */
			
			sql = "SELECT 
						cat_id 
					FROM 
						t_course 
					WHERE 
						cid = :courseId ";
			queryObj = new query( datasource=application.dnsSlave );
			queryObj.addParam( name="courseId", value=courseId, cfsqltype="cf_sql_varchar" );
			rs_course = queryObj.execute( sql=sql ).getResult();
			
			
			/* 根据学期和课程号读取全校通选课可选教学任务列表 */
			
			/* TaskProps */
			/* 第3位 是否禁止学生选课 即老师已经开始成绩提交 或 考试安排已发布 */
			/* 第7位 是否撤班 */

			sql = "SELECT 
						tk.tsk_id, tk.cidx, th.tch_name, tp.campus_name, tk.task_week,
						CASE WHEN tk.task_time IS NULL THEN '-' ELSE tk.task_time END task_time,
						CASE WHEN tk.task_place IS NULL THEN '-' ELSE tk.task_place END task_place,
						tk.task_limite, tk.task_chooesd 
					FROM 
						t_common_task tk 
						INNER JOIN t_teacher th ON tk.tch_id = th.tch_id 
						INNER JOIN t_campus tp ON tk.campus_id = tp.campus_id 
					WHERE 
						tk.term_id = :termId 
						AND 
						tk.cid = :courseId 
						AND 
						substr(tk.task_prop,3,1) = '0' 
						AND 
						substr(tk.task_prop,7,1) = '0' 
					ORDER BY 
						tk.cidx ";
			queryObj = new query( datasource=application.dnsSlave );
			queryObj.addParam( name="courseId", value=courseId, cfsqltype="cf_sql_varchar" );
			queryObj.addParam( name="termId", value=termId, cfsqltype="cf_sql_char" );
			rs_task = queryObj.execute( sql=sql ).getResult();
			
		
			/* 检查学生是否已选某教学班 */
			
			sql = "SELECT 
						task_id 
					FROM 
						t_student_course 
					WHERE 
						term_id = :termId 
						AND 
						cid = :courseId 
						AND 
						stu_id = :studentId ";
			queryObj = new query( datasource=application.dnsSlave );
			queryObj.addParam( name="courseId", value=courseId, cfsqltype="cf_sql_varchar" );
			queryObj.addParam( name="termId", value=termId, cfsqltype="cf_sql_char" );
			queryObj.addParam( name="studentId", value=studentId, cfsqltype="cf_sql_varchar" );
			rs_chooser = queryObj.execute( sql=sql ).getResult();
		
		}

		
	</cfscript>
</cfsilent>
<cfif rs_task.recordCount>
	<table class="UIEditable">
		<thead>
			<tr>
				<td width="25"></td>
				<td width="40">课序号</td>
				<td><cfif rs_course.cat_id eq "S3">助教<cfelse>教师</cfif></td>
				<td width="30">人数</td>
				<td width="30">席位</td>
				<cfif rs_course.cat_id eq "S3">
					<td width="500" colspan="4">修读要求</td>
				<cfelse>
					<td width="36">校区</td>
					<td width="36">周次</td>
					<td>上课时间</td>
					<td>上课地点</td>
				</cfif>
				
			</tr>
		</thead>
		<tbody>
            <cfloop query="rs_task">
				<cfset sitLeft = rs_task.task_limite-rs_task.task_chooesd />
				<tr class="editRows">
					<td>
                        <cfif rs_chooser.recordCount and arrayFind(rs_chooser["task_id"],rs_task.tsk_id)>
								<span class="stat on"></span>
							<cfelseif sitLeft gt 0>
								<cfset string = courseId & rs_task.cidx & termId & 'C' />
								<cfset key = rs_task.tsk_id />
								<cfset sign = encrypt(string, key, "PBEWithMD5AndDES", "Hex") />
								<a href="javascript:chooseCourse('<cfoutput>#courseId#</cfoutput>','<cfoutput>#rs_task.cidx#</cfoutput>','<cfoutput>#termId#</cfoutput>','C','<cfoutput>#rs_task.tsk_id#</cfoutput>', '<cfoutput>#sign#</cfoutput>');" class="stat off"></a>
							<cfelse>
								<span class="stat peoples" title="没有空余席位"></span>
						</cfif>
					</td>
					<td><span class="index"><cfoutput>#rs_task.cidx#</cfoutput></span></td>
					<td><cfoutput>#rs_task.tch_name#</cfoutput></td>
					<td><span class="numeric"><cfoutput>#rs_task.task_limite#</cfoutput></span></td>
					<td><span class="numeric"><cfif sitLeft gt 0><cfoutput>#sitLeft#</cfoutput><cfelse>-/-</cfif></span></td>
					<cfif rs_course.cat_id eq "S3">
						<td>课程采用在线学习模式, 完成视频观看、课后作业和在线考试. 仅建议不方便在课堂听课, 具备上网条件的高年级学生修读.</td>
					<cfelse>
						<td><cfoutput>#rs_task.campus_name#</cfoutput></td>
						<td><span class="numeric"><cfoutput>#rs_task.task_week#</cfoutput></span></td>
						<td><cfoutput>#replace(mathAdvice.convertTaskTime(rs_task.task_time), ",", "<br/>", "all")#</cfoutput></td>
						<td><cfoutput>#replace(rs_task.task_place, ",", "<br/>", "all")#</cfoutput></td>
					</cfif>
				</tr>
			</cfloop>
		</tbody>
	</table>
</cfif>
